fpath="D:\pydataset\CCIRCup\char_ner_train.csv"
devpath="D:\pydataset\CCIRCup\CCIRCup.dev.bmes"
trainpath="D:\pydataset\CCIRCup\CCIRCup.train.bmes"

fpath2="D:\pydataset\CCIRCup\evaluation_public.csv"
testpath="D:\pydataset\CCIRCup\CCIRCup.test.bmes"
import random
# 生成验证集
with open(fpath,"r",encoding='utf-8') as r:
    with open(devpath,"w",encoding='utf-8') as dev:
        with open(trainpath, "w", encoding='utf-8') as train:
            pre = r.readline() ##舍去第1行
            nowline=r.readline()
            while nowline:
                temp = random.randint(0, 9)
                print(temp,'---------------------------------')
                if temp > 7: # 20%的句子做验证集
                    while len(nowline)>2:
                        line = nowline.replace(',',' ')
                        print(line[:-1])
                        dev.write(line)
                        nowline = r.readline()
                    dev.write('\n')
                else:
                    while len(nowline)>2:
                        line = nowline.replace(',',' ')
                        print(line[:-1])
                        train.write(line)
                        nowline = r.readline()
                    train.write('\n')
                nowline = r.readline()
# 生成全O的测试集
with open(fpath2,"r",encoding='utf-8') as r:
    with open(testpath, "w", encoding='utf-8') as test:
        pre = r.readline()  ##舍去第1行
        nowline = r.readline()
        while nowline:
            line = nowline.strip().split(',')
            if line[1]=='':
                test.write('\n')
            else:
                test.write(line[1]+' O\n')
            nowline = r.readline()
